home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / hulk.swf / scripts / com / markdavies / debug / DebugBox.as
Encoding:
Text File  |  2010-04-12  |  2.2 KB  |  86 lines

  1. package com.markdavies.debug
  2. {
  3.    import com.efnx.fps.FpsBox;
  4.    import flash.system.System;
  5.    import flash.text.TextField;
  6.    import flash.text.TextFieldAutoSize;
  7.    import flash.text.TextFormat;
  8.    
  9.    public class DebugBox extends TextField
  10.    {
  11.       
  12.       private static var instance:DebugBox;
  13.        
  14.       
  15.       protected var format:TextFormat;
  16.       
  17.       private var variablesArray:Array;
  18.       
  19.       private var fps:FpsBox;
  20.       
  21.       public function DebugBox()
  22.       {
  23.          variablesArray = new Array();
  24.          format = new TextFormat();
  25.          super();
  26.          if(instance)
  27.          {
  28.             throw new Error("DebugBox can only be accessed through DebugBox.getInstance()");
  29.          }
  30.       }
  31.       
  32.       public static function debug(param1:String, param2:*) : void
  33.       {
  34.          instance.variablesArray[param1] = param2.toString();
  35.          instance.render();
  36.       }
  37.       
  38.       public static function getInstance() : DebugBox
  39.       {
  40.          try
  41.          {
  42.             instance = new DebugBox();
  43.          }
  44.          catch(e:Error)
  45.          {
  46.          }
  47.          instance.setup();
  48.          return instance;
  49.       }
  50.       
  51.       public static function setAtTop() : *
  52.       {
  53.          if(instance.parent)
  54.          {
  55.             instance.parent.setChildIndex(instance,instance.parent.numChildren - 1);
  56.          }
  57.       }
  58.       
  59.       public function setup() : void
  60.       {
  61.          format.font = "Verdana";
  62.          format.color = 0;
  63.          format.size = 10;
  64.          this.autoSize = TextFieldAutoSize.LEFT;
  65.          this.defaultTextFormat = format;
  66.          this.background = true;
  67.          this.backgroundColor = 16777215;
  68.          fps = new FpsBox(instance.stage);
  69.       }
  70.       
  71.       public function render() : void
  72.       {
  73.          var _loc1_:String = null;
  74.          var _loc2_:String = null;
  75.          _loc1_ = "";
  76.          variablesArray["AA FPS"] = fps.text + " fps";
  77.          variablesArray["AA MEMORY"] = Math.round(System.totalMemory / 1048576) + " Mb";
  78.          for(_loc2_ in variablesArray)
  79.          {
  80.             _loc1_ = _loc2_ + ": " + variablesArray[_loc2_] + "\n" + _loc1_;
  81.          }
  82.          this.text = _loc1_;
  83.       }
  84.    }
  85. }
  86.